<!DOCTYPE html>
<html>
<head>
    <title>社交账号管理</title>
    <#include "/header.html">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div style="margin: 10px 0">
            <form class="layui-form layui-form-pane" action="" id="searchForm">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">身份证号</label>
                        <div class="layui-input-inline">
                            <input type="text" name="idCard" placeholder="搜索身份号" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-primary layui-border-blue" lay-submit lay-filter="form-search-btn"><i class="layui-icon layui-icon-search"></i>搜索</button>
                        <button class="layui-btn layui-btn-primary" lay-submit lay-filter="form-reset-btn"><i class="layui-icon layui-icon-refresh"></i>重置</button>
                    </div>
                </div>
            </form>
        </div>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
    </div>
</div>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
    </div>
</script>
<script type="text/html" id="currentTableStatusTpl">
    {{# if(d.status == 1){ }}
    <span class="layui-badge layui-bg-green">启用</span>
    {{# } else { }}
    <span class="layui-badge layui-bg-grey">禁用</span>
    {{# } }}
</script>

<script type="text/html" id="currentTableBar">
	<#if shiro.hasPermission("app:userextra:save")>
    <a class="layui-btn layui-btn-primary layui-border-blue layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>修改</a>
    </#if>
    <#if shiro.hasPermission("app:userextra:delete")>
    <a class="layui-btn layui-btn-primary layui-border-red layui-btn-xs" lay-event="delete"><i class="layui-icon layui-icon-delete"></i>删除</a>
    </#if>
</script>

<script type="text/javascript">
    var formDataId = 0;
    layui.use(['form', 'table', 'laytpl'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        tableSearch({},'user/social/list');
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                formDataId = data.id;
                openFormView('app/user_social_account/form.html', '编辑');
            }else if (obj.event === 'delete') {
                layer.confirm('确定删除 '+data.name+' 吗？', function (index) {
                    deleteTableRow('user/social/delete/', [data.id], function (rs) {
                    	obj.del();
                    });
                    layer.close(index);
                });
            }
        });
        function tableSearch(data,url) {
        	var tablethis = table.render({
                elem: '#currentTableId',
			    where:data,
                url: serverUrl(url),
                toolbar: true,
                // defaultToolbar: ['filter'],
                cols: [[
                    {type: "numbers", width: 80},
                    {field: 'name', title: '商家姓名', width: 90},
                    {field: 'idard', title: '身份证号', width: 200},
                    {field: 'appId', title: 'app_id', width: 90},
                    {field: 'appName', title: 'app_name', width: 90},
                    {field: 'openId', title: 'open_id', width: 90},
                    {field: 'phone', title: '联系电话', width: 120},
                    {field: 'accountInfo', title: '现金余额', width: 120},
                    {field: 'createTime', title: '更新时间', width: 120},
                   {fixed: 'right',title: '操作', width: 150, toolbar: '#currentTableBar', align: "center"}
                ]],
                limits: [15, 30, 50],
                limit: 15,
    		 	done: function (res, curr, count){
    				  $('currentTableId').css('width', '50%');
    				  //这里设置表格的宽度为100%
    				  },
                page: true
            });
        	return tablethis;
        };
        // 监听搜索操作
        form.on('submit(form-search-btn)', function (data) {
            //执行搜索重载
            if (data.field.idCard) {
            	tableSearch({"idCard":data.field.idCard},'user/social/search');
            //table.filterData(data.field.mobile);
	        } else {
	            table.clearFilter();
	        }
	        return false;
	    });
        form.on('submit(form-reset-btn)', function (data) {
            tableSearch({},'user/social/list');
            $("#searchForm")[0].reset();
            table.clearFilter();
            return false;
        });

    });
</script>

</body>
</html>